<?php
//$Id: App.php 522 2012-08-15 09:22:00Z tomqin@gmail.com $

/**
 * The App Class
 *
 * @copyright   Copyright (C) 2010-2012 SupeFun.com Inc.
 * @author      TomQin <tomqin@gmail.com>
 * @license     http://www.supefun.com/license/
 */

class App{

    protected function __construct(){}

    /**
     * 基本信息
     */
    protected $action = null;

    function runAction($action, $param1, $param2){
        $appname = $this->getAppName();
        $action  = empty($action) ? 'Default' : $action;
        $class   = ucfirst($action).'Action';

        Core::import("apps.{$appname}.action.{$class}");
        if(class_exists($class)){
            $this->action = new $class;
            $this->action->setRoute($param1, $param2);
            $this->action->process();
        }else{
            exit('Action class `'.$action.'` is not exists!');
        }
    }

    function getAction(){
        return $this->action;
    }

    function getActionMethod(){
        return $this->action->getMethod();
    }

    function getActionParams(){
        return $this->action->getParams();
    }

    /**
     * 城市信息
     */
    protected $cityInfo = array(); //ex: array(1, 大连, 'dl')

    public function getCityId(){
        return $this->cityInfo[0];
    }

    public function getCityName(){
        return $this->cityInfo[1];
    }

    public function getCityStr(){
        return $this->cityInfo[2];
    }

    public function getCityInfo(){
        return $this->cityInfo;
    }

    /**
     * User 信息
     */
    protected $user;

    public function getUser(){
        return $this->user;
    }

    public function getClassName(){
        return get_class($this);
    }

    public function getAppName(){
        return strtolower(substr(get_class($this), 0, -3));
    }
}

?>